package com.liming.order.controller;

import com.liming.common.pojo.dto.order.admin.OrderPageQuery;
import com.liming.common.pojo.vo.PageVO;
import com.liming.common.pojo.vo.dashboard.feign.FeignUserConsumeRankVO;
import com.liming.common.pojo.vo.order.OrderVO;
import com.liming.common.pojo.vo.order.openfeign.FeignOrderDetailVO;
import com.liming.common.result.LMResult;
import com.liming.order.service.OrderMircoService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author liming
 * @date 2025/2/28
 */
@RestController
@AllArgsConstructor
@RequestMapping("/service/admin-order")
public class AdminOrderMircoController {

    private final OrderMircoService orderMircoService;

    @Operation(summary = "分页 - 订单")
    @GetMapping
    public LMResult<PageVO<OrderVO>> page(OrderPageQuery query) {
        return LMResult.success(orderMircoService.pageOrder(query));
    }

    @Operation(summary = "详情 - 订单项")
    @GetMapping("detail/{id}")
    public LMResult<FeignOrderDetailVO> detail(@PathVariable Long id) {
        return LMResult.success(orderMircoService.orderItemById(id));
    }

    @Operation(summary = "待处理订单数量")
    @GetMapping("undeliveredOrderCount")
    public LMResult<Long> undeliveredOrderCount() {
        Long result = orderMircoService.undeliveredOrderCount();
        return LMResult.success(result);
    }

    @Operation(summary = "用户消费排行")
    @PostMapping("userConsumeRank")
    public LMResult<List<FeignUserConsumeRankVO>> userConsumeRank(@RequestBody Map<Long, String> userIdAndNickname) {
        return LMResult.success(orderMircoService.userConsumeRank(userIdAndNickname));
    }

    @Operation(summary = "完成 - 订单")
    @PutMapping("complete/{id}")
    public LMResult<Boolean> complete(@PathVariable Long id) {
        return LMResult.success(orderMircoService.complete(id));
    }

    @Operation(summary = "取消 - 订单")
    @PutMapping("cancel/{id}")
    public LMResult<Boolean> cancel(@PathVariable Long id) {
        return LMResult.success(orderMircoService.cancel(id));
    }

    @Operation(summary = "发货|自提 - 订单")
    @PutMapping("deliverOrPickup/{id}")
    public LMResult<Boolean> deliverOrPickup(@PathVariable Long id) {
        return LMResult.success(orderMircoService.deliverOrPickup(id));
    }
}
